#include "StdAfx.h"
#include "DUIBuffer.h"

CDUIBuffer::CDUIBuffer(void)
{
	m_pBuffer = NULL;
	m_lSize = 0;
}

CDUIBuffer::~CDUIBuffer(void)
{
	if (m_pBuffer)
	{
		delete [] m_pBuffer;
		m_pBuffer = NULL;
	}
}


/////////////////////////////////////////////////////////////////////////////
// CUSBuffer

STDMETHODIMP CDUIBuffer::SetBuffer(const void* pData, ULONG lSize)
{
	if (NULL == pData || lSize <= 0)
	{
		return E_INVALIDARG;
	}

	if (m_pBuffer)
	{
		delete []m_pBuffer;
	}

	m_lSize = lSize;
	m_pBuffer = new byte[lSize];
	memcpy(m_pBuffer, pData, lSize);
	return S_OK;
}

STDMETHODIMP_(const void*) CDUIBuffer::GetBuffer()
{
	return m_pBuffer;
}

STDMETHODIMP_(ULONG) CDUIBuffer::GetSize()
{
	return m_lSize;
}
